package com.store;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.jedi.BaseObj;
import com.jedi.Role;
import com.jedi.User;
import com.tss.util.DbConn;
import com.tss.util.DbRs;

public class PalmonthvMgr  extends BaseObj{
	
	public Palmonthv get(String y ,String m) {
		clearErr();
		Palmonthv palmonth = new Palmonthv();
		DbConn conn = new DbConn();
		try {
			String sql = "";
			sql = "select * from palmonthv where y=? and m=?";
			conn.prepare(sql);
			conn.setString(1,y);
			conn.setString(2,m);
			DbRs rs = conn.executeQuery();
			if (rs == null || rs.size() ==0) return null;
			palmonth.setCfee(getDouble(rs,0,"cfee"));
			palmonth.setHfee(getDouble(rs,0,"hfee"));
			palmonth.setInfee(getDouble(rs,0,"infee"));
			palmonth.setM(getInt(rs,0,"m"));
			palmonth.setOutfee(getDouble(rs,0,"outfee"));
			palmonth.setPfee(getDouble(rs,0,"pfee"));
			palmonth.setPmfee(getDouble(rs,0,"pmfee"));
			palmonth.setTfee(getDouble(rs,0,"tfee"));
			palmonth.setTripfee(getDouble(rs,0,"tripfee"));
			palmonth.setUpfee(getDouble(rs,0,"upfee"));
			palmonth.setWfee(getDouble(rs,0,"wfee"));
			palmonth.setY(getInt(rs,0,"y"));
			return palmonth;
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return null;
		}
		finally {
			conn.close();
		}
	}
	
	
	
	public List getList(String otherSQL,String orderField) {
		clearErr();
		DbConn conn = new DbConn();
		DbRs rs = null;
		try {
			String sql = "select * from palmonthv  " +
			"where 1=1 ";
			if (otherSQL != null && !otherSQL.trim().equals("")) 
				sql += otherSQL;
			if (orderField != null && !orderField.trim().equals(""))
				sql += " order by " + orderField;
			conn.prepare(sql);
			rs = conn.executeQuery();
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return null;
		}
		finally {
			conn.close();
		}
		if (rs != null && rs.size() >0) {
			List r = new ArrayList();
			for(int i=0;i<rs.size();i++) {
				Palmonthv palmonthv = new Palmonthv();
				palmonthv.setCfee(getDouble(rs,i,"cfee"));
				palmonthv.setHfee(getDouble(rs,i,"hfee"));
				palmonthv.setM(getInt(rs,i,"m"));
				palmonthv.setOutfee(getDouble(rs,i,"outfee"));
				palmonthv.setPfee(getDouble(rs,i,"pfee"));
				palmonthv.setPmfee(getDouble(rs,i,"pmfee"));
				palmonthv.setTfee(getDouble(rs,i,"tfee"));
				palmonthv.setTripfee(getDouble(rs,i,"tripfee"));
				palmonthv.setUpfee(getDouble(rs,i,"upfee"));
				palmonthv.setWfee(getDouble(rs,i,"wfee"));
				palmonthv.setY(getInt(rs,i,"y"));

	
				r.add(palmonthv);
			}
			return r;
		}
		return null;
	}
	
	
	public List get(String otherSQL,String orderField,int pageNo, int pageSize) {
		clearErr();
		DbRs rs = null;
		DbConn conn = null;
		try {
			conn = new DbConn();
			String sqlCount = "select count(*) as total from palmonthv where 1=1";
			if (otherSQL != null && !otherSQL.trim().equals(""))
				sqlCount += otherSQL;
			conn.prepare(sqlCount);
			DbRs rsCount = conn.executeQuery();
			int total = getInt(rsCount,0,"total");
			setTotal(total);
			boolean b = total % pageSize == 0;
			int pageCount = b ? (total / pageSize) : (total / pageSize + 1);
			if (pageNo > pageCount) pageNo = pageCount;
			String sql = "select *  from palmonthv where 1=1 ";
			if (otherSQL != null && !otherSQL.trim().equals(""))
				sql += otherSQL;
			if (orderField != null && !orderField.trim().equals(""))
				sql += " order by " + orderField;
			conn.prepare(sql);
			rs = conn.executeQuery(pageNo, pageSize);
		} catch (SQLException ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return new ArrayList();
		} catch (Exception e) {
			e.printStackTrace();
			setErr(e.getMessage());
			return new ArrayList();
		} finally {
			conn.close();
		}
		List r = new ArrayList();
		if (rs == null || rs.size() <= 0)
			return r;
		for (int i = 0; i < rs.size(); i++) {
			Palmonthv palmonthv = new Palmonthv();
			palmonthv.setCfee(getDouble(rs,i,"cfee"));
			palmonthv.setHfee(getDouble(rs,i,"hfee"));
			palmonthv.setM(getInt(rs,i,"m"));
			palmonthv.setOutfee(getDouble(rs,i,"outfee"));
			palmonthv.setPfee(getDouble(rs,i,"pfee"));
			palmonthv.setPmfee(getDouble(rs,i,"pmfee"));
			palmonthv.setTfee(getDouble(rs,i,"tfee"));
			palmonthv.setTripfee(getDouble(rs,i,"tripfee"));
			palmonthv.setUpfee(getDouble(rs,i,"upfee"));
			palmonthv.setWfee(getDouble(rs,i,"wfee"));
			palmonthv.setInfee(getDouble(rs,i,"infee"));
			palmonthv.setY(getInt(rs,i,"y"));
			r.add(palmonthv);
		}
		return r;
	}
	/**
	 * 内部合同损益
	 * @param otherSQL
	 * @param orderField
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	public List getIn(String otherSQL,String orderField,int pageNo, int pageSize) {
		clearErr();
		DbRs rs = null;
		DbConn conn = null;
		try {
			conn = new DbConn();
			String sqlCount = "select count(*) as total from palinmonthv where 1=1";
			if (otherSQL != null && !otherSQL.trim().equals(""))
				sqlCount += otherSQL;
			conn.prepare(sqlCount);
			DbRs rsCount = conn.executeQuery();
			int total = getInt(rsCount,0,"total");
			setTotal(total);
			boolean b = total % pageSize == 0;
			int pageCount = b ? (total / pageSize) : (total / pageSize + 1);
			if (pageNo > pageCount) pageNo = pageCount;
			String sql = "select *  from palinmonthv where 1=1 ";
			if (otherSQL != null && !otherSQL.trim().equals(""))
				sql += otherSQL;
			if (orderField != null && !orderField.trim().equals(""))
				sql += " order by " + orderField;
			conn.prepare(sql);
			rs = conn.executeQuery(pageNo, pageSize);
		} catch (SQLException ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return new ArrayList();
		} catch (Exception e) {
			e.printStackTrace();
			setErr(e.getMessage());
			return new ArrayList();
		} finally {
			conn.close();
		}
		List r = new ArrayList();
		if (rs == null || rs.size() <= 0)
			return r;
		for (int i = 0; i < rs.size(); i++) {
			Palmonthv palmonthv = new Palmonthv();
			palmonthv.setCfee(getDouble(rs,i,"cfee"));
			palmonthv.setHfee(getDouble(rs,i,"hfee"));
			palmonthv.setM(getInt(rs,i,"m"));
			palmonthv.setOutfee(getDouble(rs,i,"outfee"));
			palmonthv.setPfee(getDouble(rs,i,"pfee"));
			palmonthv.setPmfee(getDouble(rs,i,"pmfee"));
			palmonthv.setTfee(getDouble(rs,i,"tfee"));
			palmonthv.setTripfee(getDouble(rs,i,"tripfee"));
			palmonthv.setUpfee(getDouble(rs,i,"upfee"));
			palmonthv.setWfee(getDouble(rs,i,"wfee"));
			palmonthv.setInfee(getDouble(rs,i,"infee"));
			palmonthv.setY(getInt(rs,i,"y"));
			r.add(palmonthv);
		}
		return r;
	}
	/**
	 * 外部合同损益
	 * @param otherSQL
	 * @param orderField
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	public List getOut(String otherSQL,String orderField,int pageNo, int pageSize) {
		clearErr();
		DbRs rs = null;
		DbConn conn = null;
		try {
			conn = new DbConn();
			String sqlCount = "select count(*) as total from paloutmonthv where 1=1";
			if (otherSQL != null && !otherSQL.trim().equals(""))
				sqlCount += otherSQL;
			conn.prepare(sqlCount);
			DbRs rsCount = conn.executeQuery();
			int total = getInt(rsCount,0,"total");
			setTotal(total);
			boolean b = total % pageSize == 0;
			int pageCount = b ? (total / pageSize) : (total / pageSize + 1);
			if (pageNo > pageCount) pageNo = pageCount;
			String sql = "select *  from paloutmonthv where 1=1 ";
			if (otherSQL != null && !otherSQL.trim().equals(""))
				sql += otherSQL;
			if (orderField != null && !orderField.trim().equals(""))
				sql += " order by " + orderField;
			conn.prepare(sql);
			rs = conn.executeQuery(pageNo, pageSize);
		} catch (SQLException ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return new ArrayList();
		} catch (Exception e) {
			e.printStackTrace();
			setErr(e.getMessage());
			return new ArrayList();
		} finally {
			conn.close();
		}
		List r = new ArrayList();
		if (rs == null || rs.size() <= 0)
			return r;
		for (int i = 0; i < rs.size(); i++) {
			Palmonthv palmonthv = new Palmonthv();
			palmonthv.setCfee(getDouble(rs,i,"cfee"));
			palmonthv.setHfee(getDouble(rs,i,"hfee"));
			palmonthv.setM(getInt(rs,i,"m"));
			palmonthv.setOutfee(getDouble(rs,i,"outfee"));
			palmonthv.setPfee(getDouble(rs,i,"pfee"));
			palmonthv.setPmfee(getDouble(rs,i,"pmfee"));
			palmonthv.setTfee(getDouble(rs,i,"tfee"));
			palmonthv.setTripfee(getDouble(rs,i,"tripfee"));
			palmonthv.setUpfee(getDouble(rs,i,"upfee"));
			palmonthv.setWfee(getDouble(rs,i,"wfee"));
			palmonthv.setInfee(getDouble(rs,i,"infee"));
			palmonthv.setY(getInt(rs,i,"y"));
			r.add(palmonthv);
		}
		return r;
	}
	
/*	
	public List get(String otherSQL,String orderField,int pageNo, int pageSize) {
		clearErr();
		DbRs rs = null;
		DbConn conn = null;
		try {
			conn = new DbConn();
			String sqlCount = "select count(*) as total from palmonthv where 1=1";
			if (otherSQL != null && !otherSQL.trim().equals(""))
				sqlCount += otherSQL;
			conn.prepare(sqlCount);
			DbRs rsCount = conn.executeQuery();
			int total = getInt(rsCount,0,"total");
			setTotal(total);
			boolean b = total % pageSize == 0;
			int pageCount = b ? (total / pageSize) : (total / pageSize + 1);
			if (pageNo > pageCount) pageNo = pageCount;
			String sql = "select *  from palmonthv where 1=1";
			if (otherSQL != null && !otherSQL.trim().equals(""))
				sql += otherSQL;
			if (orderField != null && !orderField.trim().equals(""))
				sql += " order by " + orderField;
			conn.prepare(sql);
			rs = conn.executeQuery(pageNo, pageSize);
		} catch (SQLException ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return new ArrayList();
		} catch (Exception e) {
			e.printStackTrace();
			setErr(e.getMessage());
			return new ArrayList();
		} finally {
			conn.close();
		}
		List r = new ArrayList();
		if (rs == null || rs.size() <= 0)
			return r;
		for (int i = 0; i < rs.size(); i++) {
			Palmonthv palmonthv = new Palmonthv();
			palmonthv.setCfee(getDouble(rs,i,"cfee"));
			palmonthv.setHfee(getDouble(rs,i,"hfee"));
			palmonthv.setM(getInt(rs,i,"m"));
			palmonthv.setOutfee(getDouble(rs,i,"outfee"));
			palmonthv.setPfee(getDouble(rs,i,"pfee"));
			palmonthv.setPmfee(getDouble(rs,i,"pmfee"));
			palmonthv.setTfee(getDouble(rs,i,"tfee"));
			palmonthv.setTripfee(getDouble(rs,i,"tripfee"));
			palmonthv.setUpfee(getDouble(rs,i,"upfee"));
			palmonthv.setWfee(getDouble(rs,i,"wfee"));
			palmonthv.setY(getInt(rs,i,"y"));
			r.add(palmonthv);
		}
		return r;
	}*/
}
